﻿
using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using InnovaApp.Layers.DomainLayer;

namespace InnovaApp.Layers.DataLayer
{
    public interface IRepository<T> where T : class
    {    
		#region	Methods
	
        T GetById(int id);
        IEnumerable<T> GetAll();
        IEnumerable<T> Query(Expression<Func<T, bool>> filter);        
        void Add(T entity);
        void Remove(T entity);   
		
		#endregion
    }
	
	public abstract class Repository<T> : IRepository<T>
                                  where T : class
    {
    	#region Members
    	protected readonly IObjectSet<T> _objectSet;

    	#endregion

    	#region Ctor

    	public Repository(DataRepositories repository)
    	{
      		_objectSet = repository._context.CreateObjectSet<T>();
			repository.Saved += new EventHandler(this.OnSave);
    	}
		


    	#endregion

		protected abstract void OnSave(object sender, EventArgs arg);


    	#region IRepository<T> Members

    	public IEnumerable<T> GetAll()
    	{
      		return _objectSet;
    	}

    	public abstract T GetById(int id);

    	public IEnumerable<T> Query(Expression<Func<T, bool>> filter)
    	{
      		return _objectSet.Where(filter);
    	}

    	public void Add(T entity)
    	{
     	 	_objectSet.AddObject(entity);
    	}

    	public void Remove(T entity)
    	{
      		_objectSet.DeleteObject(entity);
    	}

    	#endregion
  	}

	
	public partial class AddressType_Rep : Repository<AddressType>
	{
		#region Ctor

		public AddressType_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<AddressType,AddressType>> _entityToSync = new List<Tuple<AddressType,AddressType>>();

		#region Methods
 				
		public override AddressType GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(AddressType entity)
		{
			AddressType efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new AddressType();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new AddressType();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< AddressType,AddressType>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.Name =  entity.Name; 
						efEntity.Description =  entity.Description; 
						efEntity.isDelivery =  entity.isDelivery; 
						efEntity.isBilling =  entity.isBilling; 
						
			//Navigation Properties
						//efEntity.Contact__AdressType__ContactAddress =  entity.Contact__AdressType__ContactAddress; 
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class Contact_Rep : Repository<Contact>
	{
		#region Ctor

		public Contact_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<Contact,Contact>> _entityToSync = new List<Tuple<Contact,Contact>>();

		#region Methods
 				
		public override Contact GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(Contact entity)
		{
			Contact efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new Contact();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new Contact();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< Contact,Contact>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.FK_InnoAppUser =  entity.FK_InnoAppUser; 
						efEntity.FK_Genre =  entity.FK_Genre; 
						efEntity.FirstName =  entity.FirstName; 
						efEntity.LastName =  entity.LastName; 
						
			//Navigation Properties
						//efEntity.Contact__AdressType__ContactAddress =  entity.Contact__AdressType__ContactAddress; 
						//efEntity.Order =  entity.Order; 
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class Contact__AdressType__ContactAddress_Rep : Repository<Contact__AdressType__ContactAddress>
	{
		#region Ctor

		public Contact__AdressType__ContactAddress_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<Contact__AdressType__ContactAddress,Contact__AdressType__ContactAddress>> _entityToSync = new List<Tuple<Contact__AdressType__ContactAddress,Contact__AdressType__ContactAddress>>();

		#region Methods
 				
		public override Contact__AdressType__ContactAddress GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(Contact__AdressType__ContactAddress entity)
		{
			Contact__AdressType__ContactAddress efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new Contact__AdressType__ContactAddress();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new Contact__AdressType__ContactAddress();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< Contact__AdressType__ContactAddress,Contact__AdressType__ContactAddress>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.FK_AddressType =  entity.FK_AddressType; 
						efEntity.FK_ContactAddress =  entity.FK_ContactAddress; 
						efEntity.FK_Contact =  entity.FK_Contact; 
						
			//Navigation Properties
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class ContactAddress_Rep : Repository<ContactAddress>
	{
		#region Ctor

		public ContactAddress_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<ContactAddress,ContactAddress>> _entityToSync = new List<Tuple<ContactAddress,ContactAddress>>();

		#region Methods
 				
		public override ContactAddress GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(ContactAddress entity)
		{
			ContactAddress efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new ContactAddress();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new ContactAddress();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< ContactAddress,ContactAddress>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.Address_1 =  entity.Address_1; 
						efEntity.Address_2 =  entity.Address_2; 
						efEntity.Address_3 =  entity.Address_3; 
						efEntity.ZipCode =  entity.ZipCode; 
						efEntity.Town =  entity.Town; 
						efEntity.Cedex =  entity.Cedex; 
						efEntity.Country =  entity.Country; 
						
			//Navigation Properties
						//efEntity.Contact__AdressType__ContactAddress =  entity.Contact__AdressType__ContactAddress; 
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class DeliveryMode_Rep : Repository<DeliveryMode>
	{
		#region Ctor

		public DeliveryMode_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<DeliveryMode,DeliveryMode>> _entityToSync = new List<Tuple<DeliveryMode,DeliveryMode>>();

		#region Methods
 				
		public override DeliveryMode GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(DeliveryMode entity)
		{
			DeliveryMode efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new DeliveryMode();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new DeliveryMode();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< DeliveryMode,DeliveryMode>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.Name =  entity.Name; 
						efEntity.Description =  entity.Description; 
						efEntity.SortIndex =  entity.SortIndex; 
						
			//Navigation Properties
						//efEntity.Order =  entity.Order; 
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class Genre_Rep : Repository<Genre>
	{
		#region Ctor

		public Genre_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<Genre,Genre>> _entityToSync = new List<Tuple<Genre,Genre>>();

		#region Methods
 				
		public override Genre GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(Genre entity)
		{
			Genre efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new Genre();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new Genre();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< Genre,Genre>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.Name =  entity.Name; 
						efEntity.Description =  entity.Description; 
						efEntity.SortIndex =  entity.SortIndex; 
						
			//Navigation Properties
						//efEntity.Contact =  entity.Contact; 
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class InnoApplication_Rep : Repository<InnoApplication>
	{
		#region Ctor

		public InnoApplication_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<InnoApplication,InnoApplication>> _entityToSync = new List<Tuple<InnoApplication,InnoApplication>>();

		#region Methods
 				public InnoApplication GetById(Guid id)   
		{
			return _objectSet.SingleOrDefault(e => e.Id == id);
		}
		
				
		public override InnoApplication GetById(int id)   
		{
		 				//Implicit conversion
		return GetById(id);
				}

		public void AddUpdate(InnoApplication entity)
		{
			InnoApplication efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Guid))
			{
				efEntity = new InnoApplication();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new InnoApplication();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< InnoApplication,InnoApplication>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.FK_Language =  entity.FK_Language; 
						efEntity.Name =  entity.Name; 
						efEntity.Description =  entity.Description; 
						efEntity.DenyRobotIndexing =  entity.DenyRobotIndexing; 
						
			//Navigation Properties
						//efEntity.InnoAppUser =  entity.InnoAppUser; 
						//efEntity.LayoutMenu =  entity.LayoutMenu; 
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class InnoAppUser_Rep : Repository<InnoAppUser>
	{
		#region Ctor

		public InnoAppUser_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<InnoAppUser,InnoAppUser>> _entityToSync = new List<Tuple<InnoAppUser,InnoAppUser>>();

		#region Methods
 				public InnoAppUser GetById(Guid id)   
		{
			return _objectSet.SingleOrDefault(e => e.Id == id);
		}
		
				
		public override InnoAppUser GetById(int id)   
		{
		 				//Implicit conversion
		return GetById(id);
				}

		public void AddUpdate(InnoAppUser entity)
		{
			InnoAppUser efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Guid))
			{
				efEntity = new InnoAppUser();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new InnoAppUser();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< InnoAppUser,InnoAppUser>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.FK_Application =  entity.FK_Application; 
						efEntity.CreationDate =  entity.CreationDate; 
						efEntity.Username =  entity.Username; 
						efEntity.Email =  entity.Email; 
						efEntity.Password =  entity.Password; 
						efEntity.PasswordQuestion =  entity.PasswordQuestion; 
						efEntity.PasswordAnswer =  entity.PasswordAnswer; 
						efEntity.IsApproved =  entity.IsApproved; 
						efEntity.LastActivityDate =  entity.LastActivityDate; 
						efEntity.LastLoginDate =  entity.LastLoginDate; 
						efEntity.LastPasswordChangedDate =  entity.LastPasswordChangedDate; 
						efEntity.IsOnline =  entity.IsOnline; 
						efEntity.IsLockedOut =  entity.IsLockedOut; 
						efEntity.LastLockedOutDate =  entity.LastLockedOutDate; 
						efEntity.FailedPasswordAttemptCount =  entity.FailedPasswordAttemptCount; 
						efEntity.FailedPasswordAttemptWindowStart =  entity.FailedPasswordAttemptWindowStart; 
						efEntity.FailedPasswordAnswerAttemptCount =  entity.FailedPasswordAnswerAttemptCount; 
						efEntity.FailedPasswordAnswerAttemptWindowStart =  entity.FailedPasswordAnswerAttemptWindowStart; 
						efEntity.LastModified =  entity.LastModified; 
						efEntity.Comment =  entity.Comment; 
						efEntity.IsAnonymous =  entity.IsAnonymous; 
						
			//Navigation Properties
						//efEntity.Contact =  entity.Contact; 
						//efEntity.InnoUsersInRoles =  entity.InnoUsersInRoles; 
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class InnoProfile_Rep : Repository<InnoProfile>
	{
		#region Ctor

		public InnoProfile_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<InnoProfile,InnoProfile>> _entityToSync = new List<Tuple<InnoProfile,InnoProfile>>();

		#region Methods
 				public InnoProfile GetById(Guid id)   
		{
			return _objectSet.SingleOrDefault(e => e.Id == id);
		}
		
				
		public override InnoProfile GetById(int id)   
		{
		 				//Implicit conversion
		return GetById(id);
				}

		public void AddUpdate(InnoProfile entity)
		{
			InnoProfile efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Guid))
			{
				efEntity = new InnoProfile();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new InnoProfile();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< InnoProfile,InnoProfile>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.PropertyNames =  entity.PropertyNames; 
						efEntity.PropertyValuesString =  entity.PropertyValuesString; 
						efEntity.PropertyValuesBinary =  entity.PropertyValuesBinary; 
						efEntity.LastUpdatedDate =  entity.LastUpdatedDate; 
						
			//Navigation Properties
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class InnoRole_Rep : Repository<InnoRole>
	{
		#region Ctor

		public InnoRole_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<InnoRole,InnoRole>> _entityToSync = new List<Tuple<InnoRole,InnoRole>>();

		#region Methods
 				public InnoRole GetById(Guid id)   
		{
			return _objectSet.SingleOrDefault(e => e.Id == id);
		}
		
				
		public override InnoRole GetById(int id)   
		{
		 				//Implicit conversion
		return GetById(id);
				}

		public void AddUpdate(InnoRole entity)
		{
			InnoRole efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Guid))
			{
				efEntity = new InnoRole();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new InnoRole();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< InnoRole,InnoRole>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.FK_Application =  entity.FK_Application; 
						efEntity.Name =  entity.Name; 
						
			//Navigation Properties
						//efEntity.InnoUsersInRoles =  entity.InnoUsersInRoles; 
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class InnoUsersInRoles_Rep : Repository<InnoUsersInRoles>
	{
		#region Ctor

		public InnoUsersInRoles_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.FK_InnoRole = e.Item2.FK_InnoRole;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<InnoUsersInRoles,InnoUsersInRoles>> _entityToSync = new List<Tuple<InnoUsersInRoles,InnoUsersInRoles>>();

		#region Methods
 				public InnoUsersInRoles GetById(Guid id)   
		{
			return _objectSet.SingleOrDefault(e => e.FK_InnoRole == id);
		}
		
				
		public override InnoUsersInRoles GetById(int id)   
		{
		 				//Implicit conversion
		return GetById(id);
				}

		public void AddUpdate(InnoUsersInRoles entity)
		{
			InnoUsersInRoles efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.FK_InnoRole == default(Guid))
			{
				efEntity = new InnoUsersInRoles();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.FK_InnoRole);

				 if(efEntity == null)
				 {
				    efEntity =  new InnoUsersInRoles();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< InnoUsersInRoles,InnoUsersInRoles>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.FK_InnoAppUser =  entity.FK_InnoAppUser; 
						
			//Navigation Properties
						
				//id is set by DB
			entity.FK_InnoRole = efEntity.FK_InnoRole ; 
			
						
		}
		#endregion		
	}
	
	public partial class Language_Rep : Repository<Language>
	{
		#region Ctor

		public Language_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<Language,Language>> _entityToSync = new List<Tuple<Language,Language>>();

		#region Methods
 				
		public override Language GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(Language entity)
		{
			Language efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new Language();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new Language();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< Language,Language>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.Name =  entity.Name; 
						efEntity.Description =  entity.Description; 
						
			//Navigation Properties
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class LayoutMenu_Rep : Repository<LayoutMenu>
	{
		#region Ctor

		public LayoutMenu_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<LayoutMenu,LayoutMenu>> _entityToSync = new List<Tuple<LayoutMenu,LayoutMenu>>();

		#region Methods
 				
		public override LayoutMenu GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(LayoutMenu entity)
		{
			LayoutMenu efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new LayoutMenu();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new LayoutMenu();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< LayoutMenu,LayoutMenu>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.FK_InnoApplication =  entity.FK_InnoApplication; 
						efEntity.FK_LayoutMenu =  entity.FK_LayoutMenu; 
						efEntity.Name =  entity.Name; 
						efEntity.Controller =  entity.Controller; 
						efEntity.DefaultAction =  entity.DefaultAction; 
						efEntity.ToolTip =  entity.ToolTip; 
						efEntity.ClasseCss =  entity.ClasseCss; 
						efEntity.SortIndex =  entity.SortIndex; 
						
			//Navigation Properties
						//efEntity.LayoutMenu1 =  entity.LayoutMenu1; 
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class Lookup_Rep : Repository<Lookup>
	{
		#region Ctor

		public Lookup_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<Lookup,Lookup>> _entityToSync = new List<Tuple<Lookup,Lookup>>();

		#region Methods
 				
		public override Lookup GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(Lookup entity)
		{
			Lookup efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new Lookup();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new Lookup();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< Lookup,Lookup>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.Name =  entity.Name; 
						efEntity.Description =  entity.Description; 
						efEntity.SortIndex =  entity.SortIndex; 
						
			//Navigation Properties
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class Order_Rep : Repository<Order>
	{
		#region Ctor

		public Order_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<Order,Order>> _entityToSync = new List<Tuple<Order,Order>>();

		#region Methods
 				
		public override Order GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(Order entity)
		{
			Order efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new Order();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new Order();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< Order,Order>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.FK_DeliveryMode =  entity.FK_DeliveryMode; 
						efEntity.FK_Contact =  entity.FK_Contact; 
						efEntity.DeliveryAddress =  entity.DeliveryAddress; 
						efEntity.InvoiceAddress =  entity.InvoiceAddress; 
						efEntity.OrderRef =  entity.OrderRef; 
						efEntity.OrderDate =  entity.OrderDate; 
						efEntity.PackageCount =  entity.PackageCount; 
						efEntity.ExclusiveOfTaxeTotal =  entity.ExclusiveOfTaxeTotal; 
						efEntity.VATAmount =  entity.VATAmount; 
						efEntity.AllTaxeInclusiveTotal =  entity.AllTaxeInclusiveTotal; 
						efEntity.IsDraft =  entity.IsDraft; 
						
			//Navigation Properties
						//efEntity.OrderDetail =  entity.OrderDetail; 
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class OrderDetail_Rep : Repository<OrderDetail>
	{
		#region Ctor

		public OrderDetail_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<OrderDetail,OrderDetail>> _entityToSync = new List<Tuple<OrderDetail,OrderDetail>>();

		#region Methods
 				
		public override OrderDetail GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(OrderDetail entity)
		{
			OrderDetail efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new OrderDetail();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new OrderDetail();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< OrderDetail,OrderDetail>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.FK_Order =  entity.FK_Order; 
						efEntity.FK_Product =  entity.FK_Product; 
						efEntity.ProductDescription =  entity.ProductDescription; 
						efEntity.Quantity =  entity.Quantity; 
						efEntity.UnitPrice =  entity.UnitPrice; 
						efEntity.AppliedVATRate =  entity.AppliedVATRate; 
						efEntity.TotalPrice =  entity.TotalPrice; 
						efEntity.VatTotal =  entity.VatTotal; 
						efEntity.AllTaxeIncludedTotal =  entity.AllTaxeIncludedTotal; 
						
			//Navigation Properties
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class Product_Rep : Repository<Product>
	{
		#region Ctor

		public Product_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<Product,Product>> _entityToSync = new List<Tuple<Product,Product>>();

		#region Methods
 				
		public override Product GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(Product entity)
		{
			Product efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new Product();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new Product();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< Product,Product>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.FK_VAT =  entity.FK_VAT; 
						efEntity.Name =  entity.Name; 
						efEntity.Description =  entity.Description; 
						efEntity.UnitPrice =  entity.UnitPrice; 
						efEntity.Picture =  entity.Picture; 
						
			//Navigation Properties
						//efEntity.OrderDetail =  entity.OrderDetail; 
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	
	public partial class VAT_Rep : Repository<VAT>
	{
		#region Ctor

		public VAT_Rep(DataRepositories dataRepository)
   			: base(dataRepository)
		{
		}
		
		
		protected override void OnSave(object sender, EventArgs arg)
		{
		     foreach(var e in _entityToSync)
			 {
			 	e.Item1.Id = e.Item2.Id;
			 }
			 
			 _entityToSync.Clear();
		}

    	#endregion

		//used to cache entities that have been added or updated using AddUpdate()
		//This will update the 
		List<Tuple<VAT,VAT>> _entityToSync = new List<Tuple<VAT,VAT>>();

		#region Methods
 				
		public override VAT GetById(int id)   
		{
		 					return _objectSet.SingleOrDefault(e => e.Id == id);
				}

		public void AddUpdate(VAT entity)
		{
			VAT efEntity = null;
			/*/check if id equals zero (or null, depending on the type)
			if(entity.Id == default(Int32))
			{
				efEntity = new VAT();
				_objectSet.AddObject(efEntity);
			}else //id is not zero, so it should already exist in the repository
			{*/
				 efEntity = GetById(entity.Id);

				 if(efEntity == null)
				 {
				    efEntity =  new VAT();
					_objectSet.AddObject(efEntity);
					_entityToSync.Add(new Tuple< VAT,VAT>(entity, efEntity));
				 }else if(efEntity == entity) 
				 return; //if the submitted entity is the real entity used by EF, we don't need to map anything
			//}

			//copy values
					efEntity.Value =  entity.Value; 
						efEntity.Description =  entity.Description; 
						
			//Navigation Properties
						//efEntity.Product =  entity.Product; 
						
				//id is set by DB
			entity.Id = efEntity.Id ; 
			
						
		}
		#endregion		
	}
	

  public partial class DataRepositories
  {

     internal ObjectContext _context;

      internal event EventHandler Saved;
	  
	  public void Save() 
	  {
		_context.SaveChanges();
		if(Saved != null)
		{
			Saved(this, EventArgs.Empty);
		}
	  }
	  
	  
	  
	#region _repositories private fields
	  	private AddressType_Rep _AddressType_Rep;
		private Contact_Rep _Contact_Rep;
		private Contact__AdressType__ContactAddress_Rep _Contact__AdressType__ContactAddress_Rep;
		private ContactAddress_Rep _ContactAddress_Rep;
		private DeliveryMode_Rep _DeliveryMode_Rep;
		private Genre_Rep _Genre_Rep;
		private InnoApplication_Rep _InnoApplication_Rep;
		private InnoAppUser_Rep _InnoAppUser_Rep;
		private InnoProfile_Rep _InnoProfile_Rep;
		private InnoRole_Rep _InnoRole_Rep;
		private InnoUsersInRoles_Rep _InnoUsersInRoles_Rep;
		private Language_Rep _Language_Rep;
		private LayoutMenu_Rep _LayoutMenu_Rep;
		private Lookup_Rep _Lookup_Rep;
		private Order_Rep _Order_Rep;
		private OrderDetail_Rep _OrderDetail_Rep;
		private Product_Rep _Product_Rep;
		private VAT_Rep _VAT_Rep;
		#endregion
	
	#region repositories properties
		    
		public AddressType_Rep AddressType_Rep
		{
			get
			{
				if(_AddressType_Rep == null) _AddressType_Rep = new AddressType_Rep(this);
				 return _AddressType_Rep;
			}
		}
		    
		public Contact_Rep Contact_Rep
		{
			get
			{
				if(_Contact_Rep == null) _Contact_Rep = new Contact_Rep(this);
				 return _Contact_Rep;
			}
		}
		    
		public Contact__AdressType__ContactAddress_Rep Contact__AdressType__ContactAddress_Rep
		{
			get
			{
				if(_Contact__AdressType__ContactAddress_Rep == null) _Contact__AdressType__ContactAddress_Rep = new Contact__AdressType__ContactAddress_Rep(this);
				 return _Contact__AdressType__ContactAddress_Rep;
			}
		}
		    
		public ContactAddress_Rep ContactAddress_Rep
		{
			get
			{
				if(_ContactAddress_Rep == null) _ContactAddress_Rep = new ContactAddress_Rep(this);
				 return _ContactAddress_Rep;
			}
		}
		    
		public DeliveryMode_Rep DeliveryMode_Rep
		{
			get
			{
				if(_DeliveryMode_Rep == null) _DeliveryMode_Rep = new DeliveryMode_Rep(this);
				 return _DeliveryMode_Rep;
			}
		}
		    
		public Genre_Rep Genre_Rep
		{
			get
			{
				if(_Genre_Rep == null) _Genre_Rep = new Genre_Rep(this);
				 return _Genre_Rep;
			}
		}
		    
		public InnoApplication_Rep InnoApplication_Rep
		{
			get
			{
				if(_InnoApplication_Rep == null) _InnoApplication_Rep = new InnoApplication_Rep(this);
				 return _InnoApplication_Rep;
			}
		}
		    
		public InnoAppUser_Rep InnoAppUser_Rep
		{
			get
			{
				if(_InnoAppUser_Rep == null) _InnoAppUser_Rep = new InnoAppUser_Rep(this);
				 return _InnoAppUser_Rep;
			}
		}
		    
		public InnoProfile_Rep InnoProfile_Rep
		{
			get
			{
				if(_InnoProfile_Rep == null) _InnoProfile_Rep = new InnoProfile_Rep(this);
				 return _InnoProfile_Rep;
			}
		}
		    
		public InnoRole_Rep InnoRole_Rep
		{
			get
			{
				if(_InnoRole_Rep == null) _InnoRole_Rep = new InnoRole_Rep(this);
				 return _InnoRole_Rep;
			}
		}
		    
		public InnoUsersInRoles_Rep InnoUsersInRoles_Rep
		{
			get
			{
				if(_InnoUsersInRoles_Rep == null) _InnoUsersInRoles_Rep = new InnoUsersInRoles_Rep(this);
				 return _InnoUsersInRoles_Rep;
			}
		}
		    
		public Language_Rep Language_Rep
		{
			get
			{
				if(_Language_Rep == null) _Language_Rep = new Language_Rep(this);
				 return _Language_Rep;
			}
		}
		    
		public LayoutMenu_Rep LayoutMenu_Rep
		{
			get
			{
				if(_LayoutMenu_Rep == null) _LayoutMenu_Rep = new LayoutMenu_Rep(this);
				 return _LayoutMenu_Rep;
			}
		}
		    
		public Lookup_Rep Lookup_Rep
		{
			get
			{
				if(_Lookup_Rep == null) _Lookup_Rep = new Lookup_Rep(this);
				 return _Lookup_Rep;
			}
		}
		    
		public Order_Rep Order_Rep
		{
			get
			{
				if(_Order_Rep == null) _Order_Rep = new Order_Rep(this);
				 return _Order_Rep;
			}
		}
		    
		public OrderDetail_Rep OrderDetail_Rep
		{
			get
			{
				if(_OrderDetail_Rep == null) _OrderDetail_Rep = new OrderDetail_Rep(this);
				 return _OrderDetail_Rep;
			}
		}
		    
		public Product_Rep Product_Rep
		{
			get
			{
				if(_Product_Rep == null) _Product_Rep = new Product_Rep(this);
				 return _Product_Rep;
			}
		}
		    
		public VAT_Rep VAT_Rep
		{
			get
			{
				if(_VAT_Rep == null) _VAT_Rep = new VAT_Rep(this);
				 return _VAT_Rep;
			}
		}
		#endregion
  }
	
		
  
}
